package com.intelligentcar.springboot.controller;

import com.intelligentcar.springboot.bean.Driversalary;
import com.intelligentcar.springboot.bean.News;
import com.intelligentcar.springboot.service.DriversalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class DriversalaryController {

    @Autowired
    DriversalaryService driversalaryService;

    @RequestMapping("/LookDriverPay")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list(@RequestBody Driversalary driversalary) {
        Map map = new HashMap();
        if (driversalary.getInput().equals("") || driversalary.getInput()==""){
            List<Driversalary> list = driversalaryService.LookLook(driversalary);
            map.put("list", list);
            map.put("total", driversalaryService.selectPayroll());
        }
        for(int i=driversalary.getInput().length();--i>=0;) {
            int chr = driversalary.getInput().charAt(i);
            if (chr < 48 || chr > 57) {
                List<Driversalary> list = driversalaryService.LookLook(driversalary);
                map.put("list", list);
                map.put("total", driversalaryService.selectPayroll());
            } else {
//                driversalary.setTime(driversalary.getInput());
                System.out.println(driversalary.getInput());
                List<Driversalary> list = driversalaryService.LookTime(driversalary.getInput());
                map.put("list", list);
                map.put("total", driversalaryService.selectPayroll());
            }
        }
        return map;
    }


    //    司机薪资数据展示
    @RequestMapping("/LookDriversalary")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list() {
        List<Driversalary> list = driversalaryService.Payroll();
        Map map = new HashMap();
        map.put("list", list);
        map.put("total",driversalaryService.selectPayroll());
        return map;
    }


    //
    @RequestMapping("/updateDriversalary")
    @ResponseBody //跳过视图解析器,直接返回数据
    public int updatePayroll(@RequestBody Driversalary driversalary) {
        int a = driversalaryService.updatePayroll(driversalary.getId());
        return a;
    }

    @RequestMapping("/updataPay")
    @ResponseBody //跳过视图解析器,直接返回数据
    public int updateP(@RequestBody Driversalary driversalary) {
        int a = driversalaryService.updateP(driversalary.getId(),driversalary.getDrivername(),driversalary.getSalary(),driversalary.getTax(),
                driversalary.getInsurance(),driversalary.getElsededuct(),driversalary.getPracticalSalary(),driversalary.getTime(),
                driversalary.getState());
        return a;
    }
    //司机薪资删除信息操作
    @RequestMapping("/delPPP")//请求路径
    @ResponseBody //跳过视图解析器,直接返回数据
    public int delete(@RequestBody Driversalary driversalary){
        int delete=driversalaryService.deleteP((int)driversalary.getId());
        if (delete==1){
            return 1;
        }
        return 0;
    }

    //司机新增信息操作
    @RequestMapping("/addP")
    @ResponseBody //跳过视图解析器,直接返回数据
    public Map<String, Object> add(@RequestBody Driversalary driversalary) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", driversalaryService.addP(driversalary));
        return map;
    }
}
